package testLayer;

import static org.junit.Assert.*;

import modelLayer.Teacher;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import dbLayer.DBTeacher;

public class TeacherDatabaseTest {
	
	private DBTeacher dbTeacher;
	
	@Before
	public void setUp() throws Exception {
		
		this.dbTeacher = new DBTeacher();
		this.insert();
		
	}
	
	@After
	public void tearDown() throws Exception {
		
		this.remove();
		this.dbTeacher = null;
		
	}
	
	@Test
	public void insert() throws Exception {
		

		assertTrue(this.dbTeacher.insert(new Teacher("Ole Test", "120489-5677", "Hobrovej 12", 
											  		 "98121212", "ole@omail.dk", 12)) > 0);
		
	}
	
	@Test
	public void find() throws Exception {
		
		assertNotNull(this.dbTeacher.find("Ole Test").get(0));

	}
	
	@Test
	public void findById() throws Exception {
		
		assertNotNull(this.dbTeacher.findById(this.dbTeacher.find("Ole Test").get(0).getId()));

	}
	
	@Test
	public void getAll() throws Exception {
		
		assertTrue(!this.dbTeacher.getAll().isEmpty() && 1 <= this.dbTeacher.getAll().size());

	}
	
	@Test
	public void update() throws Exception {
		
		assertTrue(this.dbTeacher.update(this.dbTeacher.find("Ole Test").get(0).getId(),
								  "Ole Test", "120489-5677", "Hobrovej 12", 
				  				  "98121212", "ole@omail.dk", 12) > 0);
		
	}
	
	@Test
	public void remove() throws Exception {
		
		assertTrue(this.dbTeacher.remove(this.dbTeacher.find("Ole Test").get(0).getId()) > 0);
		
	} 

}
